﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TaiwuModFramework.Common.Abstract {
    public abstract class ASerializer {
        /// <summary>
        /// 序列化对象
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns>序列化后的字节数组</returns>
        public abstract byte[] Serialize(object obj);

        /// <summary>
        /// 反序列化对象
        /// </summary>
        /// <param name="data">对象的字节数组</param>
        /// <returns></returns>
        public abstract object Deserialize(byte[] data);

        /// <summary>
        /// 反序列化对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="data">对象的字节数组</param>
        /// <returns>反序列化后的对象</returns>
        public T Deseriallize<T>(byte[] data) {
            return (T)Deserialize(data);
        }
    }
}
